﻿CKEDITOR.plugins.add('multiimage', {
    init: function(editor){
        var b = editor.addCommand('multiimage', {
			exec: function( editor ) {
				var finder = new CKFinder();
				//finder.basePath = '{$WebPublic}ckfinder'; 
				finder.selectActionFunction = function(url, data, allfiles){
					var html = "";
					var n = 0;
					for(var i = 0; i < allfiles.length; i++){
						//当按回车选择时，最后一个有重复，所以需要去重
						if(i>0 && allfiles[i].url == allfiles[i-1].url) continue;
						var fileUrl = allfiles[i].url;
						var dotPosition =fileUrl.lastIndexOf(".");  
						var ext = fileUrl.substr(dotPosition+1).toLowerCase();
						if(ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "bmp" || ext == "gif" || ext == "ico"){
							if( n > 0) html += '<br/>';
							html += '<img src="'+fileUrl+'" />';
							n++;
						}
					}
					if(html.length>0){
						editor.insertHtml( html );
					}
				};
				finder.popup(); 
			}	
		});
        editor.ui.addButton('multiimage', {
            label: "多图插入和上传（按Ctrl可选择多个图片、右键选择）",
            command: 'multiimage',
            icon: this.path + '/icon.png'
        });
    }
});